package com.itheima.controller;


import com.itheima.common.PageResults;
import com.itheima.common.R;
import com.itheima.dto.Permissionss;
import com.itheima.service.PermissionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/permissions")
public class PermissionsController {

    @Autowired
    private PermissionsService permissionsService;
    //权限组修改
    /**
     * @param
     * @param permission 权限ids
     */
    @PutMapping("/{id}")
    public R updateById(@PathVariable Long id,@RequestBody Permissionss permission) {
        permissionsService.updateById(id, permission);
        return R.success("修改成功");
    }

    /**
     * @param page
     * @param pagesize
     * @param keyword    关键字
     * @return
     */
    //权限的列表
    @GetMapping
    public PageResults findBypage(Integer page, Integer pagesize, String keyword) {
        return permissionsService.findBypage(page, pagesize, keyword);

    }

    /**
     * @param id 权限组id
     * @return
     */
    //权限组删除
    @DeleteMapping("/{id}")
    public R deleteAll(@PathVariable Long id) {
        return permissionsService.delete(id);
    }

    //权限组添加
    @PostMapping
    public R add(@RequestBody Permissionss permissionss) {

        return   permissionsService.add(permissionss);
    }

    //权限组简单列表
    @GetMapping("simple")
    public R simp(@RequestBody Permissionss permissionss) {

        return  permissionsService.simp(permissionss);

    }

    //权限组详情
    @GetMapping("/{id}")
    public Permissionss findAl(@PathVariable Long id) {
        return permissionsService.findAll(id);
    }
}
